# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# NOTE: This file is auto generated by the elixir code generator program.
# Do not edit this file manually.

defmodule GoogleApi.TestClient.V1.Api.Objects do
  @moduledoc """
  API calls for all endpoints tagged `Objects`.
  """

  alias GoogleApi.TestClient.V1.Connection
  alias GoogleApi.Gax.{Request, Response}

  @library_version Mix.Project.config() |> Keyword.get(:version, "")

  @doc """
  Batch write object metadata

  ## Parameters

  *   `connection` (*type:* `GoogleApi.TestClient.V1.Connection.t`) - Connection to server
  *   `name` (*type:* `String.t`) - Required. The name of the bucket where the objects belong. The format is
      `b/[BUCKET]`
  *   `optional_params` (*type:* `keyword()`) - Optional parameters
      *   `:alt` (*type:* `String.t`) - Data format for the response.
      *   `:body` (*type:* `GoogleApi.TestClient.V1.Model.Container.t`) - 
  *   `opts` (*type:* `keyword()`) - Call options

  ## Returns

  *   `{:ok, %{}}` on success
  *   `{:error, info}` on failure
  """
  @spec objects_batch_write(Tesla.Env.client(), String.t(), keyword(), keyword()) ::
          {:ok, nil} | {:ok, Tesla.Env.t()} | {:ok, list()} | {:error, any()}
  def objects_batch_write(connection, name, optional_params \\ [], opts \\ []) do
    optional_params_config = %{
      :alt => :query,
      :body => :body
    }

    request =
      Request.new()
      |> Request.method(:post)
      |> Request.url("/test/v1/{+name}/o:batchWrite", %{
        "name" => URI.encode(name, &URI.char_unreserved?/1)
      })
      |> Request.add_optional_params(optional_params_config, optional_params)
      |> Request.library_version(@library_version)

    connection
    |> Connection.execute(request)
    |> Response.decode(opts ++ [decode: false])
  end

  @doc """
  Deletes an object

  ## Parameters

  *   `connection` (*type:* `GoogleApi.TestClient.V1.Connection.t`) - Connection to server
  *   `bucket` (*type:* `String.t`) - Name of the bucket where the object is stored
  *   `object` (*type:* `String.t`) - object's id
  *   `optional_params` (*type:* `keyword()`) - Optional parameters
      *   `:alt` (*type:* `String.t`) - Data format for the response.
  *   `opts` (*type:* `keyword()`) - Call options

  ## Returns

  *   `{:ok, %{}}` on success
  *   `{:error, info}` on failure
  """
  @spec objects_delete(Tesla.Env.client(), String.t(), String.t(), keyword(), keyword()) ::
          {:ok, nil} | {:ok, Tesla.Env.t()} | {:ok, list()} | {:error, any()}
  def objects_delete(connection, bucket, object, optional_params \\ [], opts \\ []) do
    optional_params_config = %{
      :alt => :query
    }

    request =
      Request.new()
      |> Request.method(:delete)
      |> Request.url("/test/v1/b/{bucket}/o/{object}", %{
        "bucket" => URI.encode(bucket, &URI.char_unreserved?/1),
        "object" => URI.encode(object, &(URI.char_unreserved?(&1) || &1 == ?/))
      })
      |> Request.add_optional_params(optional_params_config, optional_params)
      |> Request.library_version(@library_version)

    connection
    |> Connection.execute(request)
    |> Response.decode(opts ++ [decode: false])
  end

  @doc """
  Gets a single object by Id.

  ## Parameters

  *   `connection` (*type:* `GoogleApi.TestClient.V1.Connection.t`) - Connection to server
  *   `bucket` (*type:* `String.t`) - Name of the bucket where the object is stored
  *   `id` (*type:* `integer()`) - The object id
  *   `optional_params` (*type:* `keyword()`) - Optional parameters
      *   `:alt` (*type:* `String.t`) - Data format for the response.
      *   `:category` (*type:* `list(String.t)`) - The category of the items. Must match all.
  *   `opts` (*type:* `keyword()`) - Call options

  ## Returns

  *   `{:ok, %GoogleApi.TestClient.V1.Model.Container{}}` on success
  *   `{:error, info}` on failure
  """
  @spec objects_get(Tesla.Env.client(), String.t(), integer(), keyword(), keyword()) ::
          {:ok, GoogleApi.TestClient.V1.Model.Container.t()}
          | {:ok, Tesla.Env.t()}
          | {:ok, list()}
          | {:error, any()}
  def objects_get(connection, bucket, id, optional_params \\ [], opts \\ []) do
    optional_params_config = %{
      :alt => :query,
      :category => :query
    }

    request =
      Request.new()
      |> Request.method(:get)
      |> Request.url("/test/v1/b/{bucket}/o/{id}", %{
        "bucket" => URI.encode(bucket, &URI.char_unreserved?/1),
        "id" => id
      })
      |> Request.add_optional_params(optional_params_config, optional_params)
      |> Request.library_version(@library_version)

    connection
    |> Connection.execute(request)
    |> Response.decode(opts ++ [struct: %GoogleApi.TestClient.V1.Model.Container{}])
  end

  @doc """
  Stores a new object and metadata

  ## Parameters

  *   `connection` (*type:* `GoogleApi.TestClient.V1.Connection.t`) - Connection to server
  *   `bucket` (*type:* `String.t`) - Name of the bucket where the object is stored
  *   `optional_params` (*type:* `keyword()`) - Optional parameters
      *   `:alt` (*type:* `String.t`) - Data format for the response.
      *   `:name` (*type:* `String.t`) - Name of the object. Required when the object metadata is not otherwise provided.
      *   `:body` (*type:* `GoogleApi.TestClient.V1.Model.Container.t`) - 
  *   `opts` (*type:* `keyword()`) - Call options

  ## Returns

  *   `{:ok, %GoogleApi.TestClient.V1.Model.Container{}}` on success
  *   `{:error, info}` on failure
  """
  @spec objects_insert(Tesla.Env.client(), String.t(), keyword(), keyword()) ::
          {:ok, GoogleApi.TestClient.V1.Model.Container.t()}
          | {:ok, Tesla.Env.t()}
          | {:ok, list()}
          | {:error, any()}
  def objects_insert(connection, bucket, optional_params \\ [], opts \\ []) do
    optional_params_config = %{
      :alt => :query,
      :name => :query,
      :body => :body
    }

    request =
      Request.new()
      |> Request.method(:post)
      |> Request.url("/test/v1/b/{bucket}/o", %{
        "bucket" => URI.encode(bucket, &URI.char_unreserved?/1)
      })
      |> Request.add_optional_params(optional_params_config, optional_params)
      |> Request.library_version(@library_version)

    connection
    |> Connection.execute(request)
    |> Response.decode(opts ++ [struct: %GoogleApi.TestClient.V1.Model.Container{}])
  end

  @doc """
  Stores a new object and metadata

  ## Parameters

  *   `connection` (*type:* `GoogleApi.TestClient.V1.Connection.t`) - Connection to server
  *   `bucket` (*type:* `String.t`) - Name of the bucket where the object is stored
  *   `upload_type` (*type:* `String.t`) - Upload type. Must be "multipart".
  *   `metadata` (*type:* `GoogleApi.TestClient.V1.Model.Container.t`) - object metadata
  *   `data` (*type:* `iodata`) - Content to upload, as a string or iolist
  *   `optional_params` (*type:* `keyword()`) - Optional parameters
      *   `:alt` (*type:* `String.t`) - Data format for the response.
      *   `:name` (*type:* `String.t`) - Name of the object. Required when the object metadata is not otherwise provided.
  *   `opts` (*type:* `keyword()`) - Call options

  ## Returns

  *   `{:ok, %GoogleApi.TestClient.V1.Model.Container{}}` on success
  *   `{:error, info}` on failure
  """
  @spec objects_insert_iodata(
          Tesla.Env.client(),
          String.t(),
          String.t(),
          GoogleApi.TestClient.V1.Model.Container.t(),
          iodata,
          keyword(),
          keyword()
        ) ::
          {:ok, GoogleApi.TestClient.V1.Model.Container.t()}
          | {:ok, Tesla.Env.t()}
          | {:ok, list()}
          | {:error, any()}
  def objects_insert_iodata(
        connection,
        bucket,
        upload_type,
        metadata,
        data,
        optional_params \\ [],
        opts \\ []
      ) do
    optional_params_config = %{
      :alt => :query,
      :name => :query
    }

    request =
      Request.new()
      |> Request.method(:post)
      |> Request.url("/upload/v1/b/{bucket}/o", %{
        "bucket" => URI.encode(bucket, &URI.char_unreserved?/1)
      })
      |> Request.add_param(:query, :uploadType, upload_type)
      |> Request.add_param(:body, :metadata, metadata)
      |> Request.add_param(:body, :data, data)
      |> Request.add_optional_params(optional_params_config, optional_params)
      |> Request.library_version(@library_version)

    connection
    |> Connection.execute(request)
    |> Response.decode(opts ++ [struct: %GoogleApi.TestClient.V1.Model.Container{}])
  end

  @doc """
  Stores a new object and metadata

  ## Parameters

  *   `connection` (*type:* `GoogleApi.TestClient.V1.Connection.t`) - Connection to server
  *   `bucket` (*type:* `String.t`) - Name of the bucket where the object is stored
  *   `upload_type` (*type:* `String.t`) - Upload type. Must be "resumable".
  *   `optional_params` (*type:* `keyword()`) - Optional parameters
      *   `:alt` (*type:* `String.t`) - Data format for the response.
      *   `:name` (*type:* `String.t`) - Name of the object. Required when the object metadata is not otherwise provided.
      *   `:body` (*type:* `GoogleApi.TestClient.V1.Model.Container.t`) - 
  *   `opts` (*type:* `keyword()`) - Call options

  ## Returns

  *   `{:ok, %{}}` on success
  *   `{:error, info}` on failure
  """
  @spec objects_insert_resumable(Tesla.Env.client(), String.t(), String.t(), keyword(), keyword()) ::
          {:ok, nil} | {:ok, Tesla.Env.t()} | {:ok, list()} | {:error, any()}
  def objects_insert_resumable(connection, bucket, upload_type, optional_params \\ [], opts \\ []) do
    optional_params_config = %{
      :alt => :query,
      :name => :query,
      :body => :body
    }

    request =
      Request.new()
      |> Request.method(:post)
      |> Request.url("/resumable/upload/v1/b/{bucket}/o", %{
        "bucket" => URI.encode(bucket, &URI.char_unreserved?/1)
      })
      |> Request.add_param(:query, :uploadType, upload_type)
      |> Request.add_optional_params(optional_params_config, optional_params)
      |> Request.library_version(@library_version)

    connection
    |> Connection.execute(request)
    |> Response.decode(opts ++ [decode: false])
  end

  @doc """
  Stores a new object and metadata

  ## Parameters

  *   `connection` (*type:* `GoogleApi.TestClient.V1.Connection.t`) - Connection to server
  *   `bucket` (*type:* `String.t`) - Name of the bucket where the object is stored
  *   `upload_type` (*type:* `String.t`) - Upload type. Must be "multipart".
  *   `metadata` (*type:* `GoogleApi.TestClient.V1.Model.Container.t`) - object metadata
  *   `data` (*type:* `String.t`) - Path to file containing content to upload
  *   `optional_params` (*type:* `keyword()`) - Optional parameters
      *   `:alt` (*type:* `String.t`) - Data format for the response.
      *   `:name` (*type:* `String.t`) - Name of the object. Required when the object metadata is not otherwise provided.
  *   `opts` (*type:* `keyword()`) - Call options

  ## Returns

  *   `{:ok, %GoogleApi.TestClient.V1.Model.Container{}}` on success
  *   `{:error, info}` on failure
  """
  @spec objects_insert_simple(
          Tesla.Env.client(),
          String.t(),
          String.t(),
          GoogleApi.TestClient.V1.Model.Container.t(),
          String.t(),
          keyword(),
          keyword()
        ) ::
          {:ok, GoogleApi.TestClient.V1.Model.Container.t()}
          | {:ok, Tesla.Env.t()}
          | {:ok, list()}
          | {:error, any()}
  def objects_insert_simple(
        connection,
        bucket,
        upload_type,
        metadata,
        data,
        optional_params \\ [],
        opts \\ []
      ) do
    optional_params_config = %{
      :alt => :query,
      :name => :query
    }

    request =
      Request.new()
      |> Request.method(:post)
      |> Request.url("/upload/v1/b/{bucket}/o", %{
        "bucket" => URI.encode(bucket, &URI.char_unreserved?/1)
      })
      |> Request.add_param(:query, :uploadType, upload_type)
      |> Request.add_param(:body, :metadata, metadata)
      |> Request.add_param(:file, :data, data)
      |> Request.add_optional_params(optional_params_config, optional_params)
      |> Request.library_version(@library_version)

    connection
    |> Connection.execute(request)
    |> Response.decode(opts ++ [struct: %GoogleApi.TestClient.V1.Model.Container{}])
  end

  @doc """
  Fetch a data-wrapped object

  ## Parameters

  *   `connection` (*type:* `GoogleApi.TestClient.V1.Connection.t`) - Connection to server
  *   `bucket` (*type:* `String.t`) - Name of the bucket where the object is stored
  *   `optional_params` (*type:* `keyword()`) - Optional parameters
      *   `:alt` (*type:* `String.t`) - Data format for the response.
  *   `opts` (*type:* `keyword()`) - Call options

  ## Returns

  *   `{:ok, %GoogleApi.TestClient.V1.Model.Container{}}` on success
  *   `{:error, info}` on failure
  """
  @spec objects_wrapped(Tesla.Env.client(), String.t(), keyword(), keyword()) ::
          {:ok, GoogleApi.TestClient.V1.Model.Container.t()}
          | {:ok, Tesla.Env.t()}
          | {:ok, list()}
          | {:error, any()}
  def objects_wrapped(connection, bucket, optional_params \\ [], opts \\ []) do
    optional_params_config = %{
      :alt => :query
    }

    request =
      Request.new()
      |> Request.method(:get)
      |> Request.url("/test/v1/b/{bucket}/wrapped", %{
        "bucket" => URI.encode(bucket, &URI.char_unreserved?/1)
      })
      |> Request.add_optional_params(optional_params_config, optional_params)
      |> Request.library_version(@library_version)

    connection
    |> Connection.execute(request)
    |> Response.decode(opts ++ [struct: %GoogleApi.TestClient.V1.Model.Container{}])
  end
end
